// xstddef standard header -*-c++-*-
// Copyright 2003-2010 IAR Systems AB. 
#ifndef _XSTDDEF_
#define _XSTDDEF_

#ifndef _SYSTEM_BUILD
  #pragma system_include
#endif

#include <ycheck.h>
#include <yvals.h>
#include <cstddef>

_STD_BEGIN

// EXCEPTION MACROS
#if _HAS_EXCEPTIONS
  #define _TRY_BEGIN     try {
  #define _CATCH(x)      } catch (x) {
  #define _CATCH_ALL     } catch (...) {
  #define _CATCH_END     }

  // Throw(raise) an exception
  #define _RAISE(x)      throw (x)
  #define _RERAISE       throw

  // Exception-specifier with one type
  #ifndef _THROWS
    #define _THROWS(x)	throw (x)
  #endif /* _THROWS */

  // Exception-specifier with zero types
  #define _THROW0()      throw ()

#if 0
  // Not used
  #define _THROW1(x)     throw (x)
#endif

  // Throw(raise) an exception x with parameter y
  #define _THROW(x, y)   throw x(y)
#else /* no exceptions */
  #define _TRY_BEGIN     {{
  #define _CATCH(x)      } if (0) {
  #define _CATCH_ALL     } if (0) {
  #define _CATCH_END     }}

  #if _DLIB_THROW_HANDLING == 0
    #include <cstdlib>
    #define _RAISE(x)      abort()
    #define _THROW(x, y)   do {} while(0)
  #elif _DLIB_THROW_HANDLING == 1
    #include <cstdlib>
    #define _RAISE(x)      abort()
    #define _THROW(x, y)   abort()
  #else /* _DLIB_THROW_HANDLING != 0, != 1 */
    #define _RAISE(x)      _Throw(x)
    #define _THROW(x, y)   x(y)._Raise()
  #endif /* _DLIB_THROW_HANDLING */
  #define _RERAISE
 
  #ifndef _THROWS
    #define _THROWS(x)
  #endif /* _THROWS */

  #define _THROW0()
  #define _THROW1(x)
#endif /* _HAS_EXCEPTIONS */

// typename KEYWORD
#ifndef _TEMPLATE_STAT
/*  #define _TEMPLATE_STAT        template<> */
#endif

#ifndef _TEMPLATE_MEMBER
/*  #define _TEMPLATE_MEMBER      template */
#endif

// BITMASK MACROS
#define _BITMASK(Enum, Ty)     typedef int Ty

#define _BITMASK_OPS(Ty) \
inline Ty& operator&=(Ty& _Left, Ty _Right) \
        {       /* return _Left &= _Right */ \
        _Left = (Ty)((int)_Left & (int)_Right); return _Left; \
        } \
\
inline Ty& operator|=(Ty& _Left, Ty _Right) \
        {       /* return _Left |= _Right */ \
        _Left = (Ty)((int)_Left | (int)_Right); return _Left; \
        } \
\
inline Ty& operator^=(Ty& _Left, Ty _Right) \
        {       /* return _Left &= _Right */ \
        _Left = (Ty)((int)_Left ^ (int)_Right); return _Left; \
        } \
\
inline Ty operator&(Ty _Left, Ty _Right) \
        {       /* return _Left & _Right */ \
        return ((Ty)((int)_Left & (int)_Right)); \
        } \
\
inline Ty operator|(Ty _Left, Ty _Right) \
        {       /* return _Left | _Right */ \
        return ((Ty)((int)_Left | (int)_Right)); \
        } \
\
inline Ty operator^(Ty _Left, Ty _Right) \
        {       /* return _Left ^ _Right */ \
        return ((Ty)((int)_Left ^ (int)_Right)); \
        } \
\
inline Ty operator~(Ty _Left) \
        {       /* return ~_Left */ \
        return ((Ty)~(int)_Left); \
        }

// MISCELLANEOUS MACROS
#define _DESTRUCTOR(ty, ptr)    (ptr)->~ty()
#define _MESG(str)      str
#define _PROTECTED      protected

#define _TDEF(x)        = x
#define _TDEF2(x, y)    = x, y

#define _STCONS(ty, name, val) static const ty name = (ty)(val)

#ifndef _XSTD
  #define _X_STD_BEGIN  _STD_BEGIN
  #define _X_STD_END    _STD_END
  #define _XSTD _STD /* LEAVE SPACE */
#endif /* _XSTD */

// TYPE DEFINITIONS
enum _Uninitialized
{       // tag for suppressing initialization
  _Noinit
};

// FUNCTIONS
__ATTRIBUTES void _Nomemory();
_STD_END
#endif /* _XSTDDEF_ */

/*
 * Copyright (c) 1992-2009 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.04:0576 */
